<?php

namespace App\Http\Middleware;

use Auth;
use Closure;
use Log;

/**
 * 检验签名
 * Class Deny
 * @package App\Http\Middleware
 */
class VerifySign
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (isMock() || !config('common.verifyApi') || ($request->input('debug') == 'XYZ')){
            return $next($request);
        }

        if (!$request->has('sign')){
            throw new \Exception('签名不正确');
        }
        ;
        if (!uc_authcode($request->input('sign'),'DECODE')){
            throw new \Exception('签名不正确');
        }

        return $next($request);
    }
}
